const app = getApp()
Page({

  data:{
    cate:'',
    date: '',
    lastremain:'',
    remainmoney:'',

  },
  radioChange: function (e) {
    this.setData({
      cate: e.detail.value
    })
    
  },

  Recharge:function(){
    if (this.data.cate) {
      let tableID = 38225
      let Product1 = new wx.BaaS.TableObject(tableID)
      let product1 = Product1.create()

      let Recharge = {
        money: this.data.cate,
        name: app.globalData.name,
        rechargedate: this.data.date
      }
      product1.set(Recharge).save()

    let tableID1 = 37774
    let Product = new wx.BaaS.TableObject(tableID1)
    let product = Product.create()
    Product.find().then(res => {
      this.setData({
        lastremain: res.data.objects[res.data.objects.length - 1].remain

      })
      this.data.remainmoney = String(parseFloat(this.data.lastremain) + parseFloat(this.data.cate))
      console.log(this.data.remainmoney)
      let Record = {
        title: app.globalData.name+'充值',
        account: this.data.cate,
        date: this.data.date,
        remain: this.data.remainmoney
      }
      product.set(Record).save()
    }, err => {
      wx.showModal({
        title: '当前数据库为空！',
      })
    })
    wx.showModal({
      title: '充值成功！',
    })// 提示框
  }else{
      wx.showModal({
        title: '未选择金额',
      })
  }
  },
  onLoad: function (options) {
    // 初始化日期
    //    获取当前日期
    var date = new Date();
    //    格式化日期为"YYYY-mm-dd"
    var dateStr = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    //    存回date，以渲染到页面

    this.setData({
      date: dateStr
    })
  },

  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
  },//日期


})

